package com.battle.service.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.battle.pojo.entity.TacticsUser;
import com.battle.pojo.param.tacticsUser.*;
import com.battle.pojo.vo.tacticsUser.*;
import com.battle.pojo.dto.tacticsUser.*;
import com.battle.service.repository.in.TacticsUserRepository;
import com.battle.service.service.in.TacticsUserService;
import nirvana.core.domains.vo.PageResult;
import nirvana.core.utils.ids.IdGenerator;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;


import java.util.ArrayList;
import java.util.List;

/**
 * 【描 述】：战术学习服务
 * 【环 境】：J2SE 17
 * 【详 细】：
 */
@Service
public class TacticsUserServiceImpl implements TacticsUserService {

    private final TacticsUserRepository tacticsUserRepository;

    public TacticsUserServiceImpl(TacticsUserRepository tacticsUserRepository) {
        this.tacticsUserRepository = tacticsUserRepository;
    }


    /**
     * 创建战术学习
     *
     * @param param
     */
    @Override
    public void createTacticsUser(CreateTacticsUserParam param) {
        TacticsUser tacticsUser = new TacticsUser();
        BeanUtils.copyProperties(param, tacticsUser);
        Long id = IdGenerator.SNOW.generate();
        tacticsUser.setId(id);
        tacticsUserRepository.create(tacticsUser);
    }

    /**
     * 修改战术学习
     *
     * @param param
     */
    @Override
    public void editTacticsUser(EditTacticsUserParam param) {
        Long id = param.getId();
        TacticsUser tacticsUser = tacticsUserRepository.getByIdCheck(id);
        BeanUtils.copyProperties(param, tacticsUser);
        tacticsUserRepository.edit(tacticsUser);
    }

    /**
     * 移除战术学习
     *
     * @param id
     */
    @Override
    public void removeTacticsUser(Long id) {
        tacticsUserRepository.removeById(id);
    }

    /**
     * 启动/禁用战术学习
     *
     * @param id
     */
    @Override
    public void enabledTacticsUser(Long id) {
        TacticsUser tacticsUser = tacticsUserRepository.getByIdCheck(id);
        tacticsUser.setIsDisable(!tacticsUser.getIsDisable());
        tacticsUserRepository.edit(tacticsUser);
    }

    /**
     * 获取战术学习详情
     *
     * @param id
     * @return
     */
    @Override
    public GetTacticsUserVo getTacticsUser(Long id) {
        TacticsUser tacticsUser = tacticsUserRepository.getByIdCheck(id);
        GetTacticsUserVo vo = new GetTacticsUserVo();
        BeanUtils.copyProperties(tacticsUser, vo);
        return vo;
    }

    /**
     * 获取战术学习 列表
     *
     * @param param
     * @return
     */
    @Override
    public PageResult<GetTacticsUserListVo> getTacticsUserList(GetTacticsUserListParam param) {

        SelectTacticsUserDto dto = new SelectTacticsUserDto();
        BeanUtils.copyProperties(param, dto);
        Page<TacticsUser> page = tacticsUserRepository.selectTacticsUser(dto);
        List<TacticsUser> tacticsUserList = page.getRecords();
        List<GetTacticsUserListVo> list = new ArrayList<>();
        for (TacticsUser tacticsUser : tacticsUserList) {
            GetTacticsUserListVo vo = new GetTacticsUserListVo();
            BeanUtils.copyProperties(tacticsUser, vo);

            list.add(vo);
        }
        return new PageResult<>(list, page);

    }

    /**
     * 获取战术学习下拉列表
     *
     * @param param
     * @return
     */
    @Override
    public List<GetTacticsUserDownListVo> getTacticsUserDownList(GetTacticsUserDownListParam param) {
        TacticsUser po = new TacticsUser();
        if (param != null) {
            BeanUtils.copyProperties(param, po);
        }
        List<TacticsUser> tacticsUserList = tacticsUserRepository.getListByEntity(po);

        List<GetTacticsUserDownListVo> list = new ArrayList<>();
        for (TacticsUser tacticsUser : tacticsUserList) {
            GetTacticsUserDownListVo vo = new GetTacticsUserDownListVo();
            BeanUtils.copyProperties(tacticsUser, vo);
            list.add(vo);
        }
        return list;
    }


}



